package com.ruoyi.checkingin.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.e_checkingin.EActuallyWage;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.temporary.PayOffEntity;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.checkingin.service.IEActuallyWageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实发工资Controller
 *
 * @author JYW
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/checkingin/wage")
public class EActuallyWageController extends BaseController
{
    @Autowired
    private IEActuallyWageService eActuallyWageService;


    /**
     * 查询实发工资列表
     */
    @PreAuthorize("@ss.hasPermi('checkingin:wage:list')")
    @GetMapping("/list")
    public TableDataInfo list(EActuallyWage eActuallyWage)
    {
        startPage();
        List<EActuallyWage> list = eActuallyWageService.selectEActuallyWageList(eActuallyWage);
        return getDataTable(list);
    }

    /**
     * 查询自己实发工资列表
     */
//    @PreAuthorize("@ss.hasPermi('checkingin:wage:list')")
    @GetMapping("/listbyMe")
    public TableDataInfo listbyMe()
    {
        startPage();
        EActuallyWage eActuallyWage = new EActuallyWage();
        eActuallyWage.setuId(SecurityUtils.getUserId());
        List<EActuallyWage> list = eActuallyWageService.selectEActuallyWageList(eActuallyWage);
        return getDataTable(list);
    }

    /**
     * 导出实发工资列表
     */
    @PreAuthorize("@ss.hasPermi('checkingin:wage:export')")
    @Log(title = "实发工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EActuallyWage eActuallyWage)
    {
        List<EActuallyWage> list = eActuallyWageService.selectEActuallyWageList(eActuallyWage);
        ExcelUtil<EActuallyWage> util = new ExcelUtil<EActuallyWage>(EActuallyWage.class);
        util.exportExcel(response, list, "实发工资数据");
    }

    /**
     * 获取实发工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('checkingin:wage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eActuallyWageService.selectEActuallyWageById(id));
    }

    /**
     * 新增实发工资
     */
    @PreAuthorize("@ss.hasPermi('checkingin:wage:add')")
    @Log(title = "实发工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add()
    {
        return toAjax(eActuallyWageService.insertEActuallyWage());
    }

    /**
     * 修改实发工资
     */
    @PreAuthorize("@ss.hasPermi('checkingin:wage:edit')")
    @Log(title = "实发工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EActuallyWage eActuallyWage)
    {
        return toAjax(eActuallyWageService.updateEActuallyWage(eActuallyWage));
    }

    /**
     * 删除实发工资
     */
    @PreAuthorize("@ss.hasPermi('checkingin:wage:remove')")
    @Log(title = "实发工资", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eActuallyWageService.deleteEActuallyWageByIds(ids));
    }

    /**
     * 按月查看公司当月工资发放详情
     * @param date
     * @return
     */
    @GetMapping("/company/payoff")
    public AjaxResult allPayOff(String date){
        if (date == null){
            date = DateUtils.parseDateToStr("yyyy-MM",new Date());
        }
        return AjaxResult.success(eActuallyWageService.allPayOff(date));
    }
}
